import os

p = input("网段：")
with open("ip.txt", "w+", encoding="utf-8") as f:
    for i in range(1, 255):
        ip = p + "." + str(i)
        try:
            re = os.system(f"ping {ip} -n 1 ")
            print(re)
            if re == 0:
                f.write(f"{ip}已被使用！\n")
            else:
                f.write(f"{ip}未被使用！\n")
        except Exception:
            print(f"{ip}出现异常")
